package com.lg.concurrent.schedule;

import lombok.SneakyThrows;

import java.util.concurrent.CountDownLatch;

/**
 * 当 down到0 之后再 await，会怎样
 *   会继续执行
 *
 * 当 down到0 之后再 down，会怎样
 *   会继续执行
 */
public class CountDownLatchDemo3 {
    @SneakyThrows
    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(2);


        new Thread(()->{
            countDownLatch.countDown();
            try {
                countDownLatch.await();

                System.out.println("thread start");
                countDownLatch.countDown();
                countDownLatch.await();
                System.out.println("thread start again");

            } catch (InterruptedException e) {
                e.printStackTrace();
            }


        }).start();


        countDownLatch.countDown();
        countDownLatch.await();

        System.out.println("main start");
        countDownLatch.countDown();
        countDownLatch.await();
        System.out.println("main start again");
    }
}
